from view.baseview import BaseView
from orm.model import AllApp

class AllAppView(BaseView):
    def __init__(self):
        pass

    def getAllApp(self):
        """取得所有App"""
        data = {}
        allapps = AllApp.select()
        #常用应用
        defaultapps = []
        #桌面应用
        desktopapps = []
        #手机应用
        phoneapps = []
        for app in allapps:
            if app.group_id.id==1:
                defaultapps.append({"id":app.id,"text":app.text,"imgsrc":app.imgsrc})
            elif app.group_id.id ==2:
                desktopapps.append({"id":app.id,"text":app.text,"imgsrc":app.imgsrc})
            elif app.group_id.id ==4:
                phoneapps.append({"id":app.id,"text":app.text,"imgsrc":app.imgsrc})    
            else:
                pass
            data = {"defaultapps":defaultapps,"desktopapps":desktopapps,"phoneapps":phoneapps}
        return super().resultSet(200, "应用列表取得成功！",  data)
